import requests


class SendMethod:

    @staticmethod
    def send_method(method,url,params=None,data=None,json=None,headers=None):
        # 封装请求
        if method == 'get':
            response = requests.get(url=url,params=params,headers=headers)
        elif method == 'post':
            response = requests.post(url=url,data=data,json=json,headers=headers)
        else:
            print("请求方法错误,不支持该请求")
            response = None
        # 封装响应
        result ={}
        if response is not None:
            result['status_code'] = response.status_code
            result['headers'] = response.headers
            result['body'] = response.json()
            result['response_time'] = int(response.elapsed.microseconds / 1000)
            return result
        else:
            return response

if __name__ == '__main__':
    url = "http://47.108.206.100:8080/admin/login"
    method = "post"
    body = {
        "username":"admin",
        "password":"macro123"
    }
    print(SendMethod.send_method(method, url, json=body))